/**
 *  @file
 *  @brief   分析工况定义
 *  @author  wanghuan
 *  @date    2024.03.31
 *  @version  v1.0
 *  @par Copyright(c):  ShenGong  Simulation corporation
 */

#pragma once
#include <string>
#include "Utility/Configuration/SGParameter.h"
#include "DataStructure/Common/DataStructureNamespace.h"
#include "DataStructure/Common/Id.h"
#include "DataStructure/Input/Solver/AnaysisTypes.h"
#include "DataStructure/Input/Dynamic/InitConditionType.h"

SG_DATASTRUCTURE_FEM_NAMESPACE_OPEN

/** @brief 分析工况数据，此类负责对单个工况的数据进行解析
 *
 */
class DECLSPEC Subcase
{
  public:
    struct ControlInfo
    {
        ControlInfo(const std::string& key):m_Key(key){}
        ControlInfo(const std::string& key, const std::string& value):m_Key(key), m_Vaule(value) {}
        ControlInfo(){};
        /// < 主键，例如 "AUTOSPC"。
        std::string m_Key;
        /// < 等号右侧的值，例如 "YES"。
        std::string m_Vaule;
        /// < 可选的参数集合，存储括号内不带值的参数，例如 "PRINT" 和 "PUNCH"。
        std::vector<std::string> m_vecKeys;
        /// < 带值的参数键值对集合，存储括号内带值的参数，例如 "SID=100" 和 "EPS=1.E-6"。
        std::map<std::string, std::string> m_mapKeys;
    };
    static const std::string SC_MAINKEY; //记录等号右侧
    static const std::string SC_VECTORKEY;//记录（）内没有value的项，是一个string array
    static const std::string SC_MAPKEY;//记录（）内有value的项，是一个Parameter

    Subcase () = default;
    Subcase (SG::Utility::SGParameter& parameter):m_parameter(parameter) {}
    ~Subcase () = default;
private:
    // @brief 内部实现与json 参数组写入
    bool ParseParameter (ControlInfo& controInfo) const;

public:
    // @brief 设置某个选项（SPC，MPC， Load 等）
    void AddParameter (const ControlInfo& controInfo);

    /// @brief 获取工况号
    SG::DataStructure::Common::Id GetSubcaseId () const;

    /// @brief 获取求解类型
    /// @return 
    SOLType GetSOLType () const;
    
    SG::DataStructure::Common::Id GetLoadId () const;
    SG::DataStructure::Common::Id GetDLoadId () const;
    SG::DataStructure::Common::Id GetSPCId () const;
    SG::DataStructure::Common::Id GetMPCId () const;
    SG::DataStructure::Common::Id GetStaticSubId () const;
    SG::DataStructure::Common::Id GetMethodId () const;
    SG::DataStructure::Common::Id GetCMethodId () const;
    SG::DataStructure::Common::Id GetTSTEPId () const;
    bool HasLoadset () const;
    SG::DataStructure::Common::Id GetLoadsetId () const;
    SG::DataStructure::Common::Id GetFrequencyId () const;
    SG::DataStructure::Common::Id GetRCROSSId () const;
    SG::DataStructure::Common::Id GetRANDPSId () const;
    SG::DataStructure::Common::Id GetSdampingId () const;
 
    /// @brief 或者初始条件
    SG::DataStructure::Common::Id GetICId (InitConditonType& type) const;
    SG::DataStructure::Common::Id GetModeSelectId () const;
    SG::DataStructure::Common::Id GetModesId () const;
    SG::DataStructure::Common::Id GetNLPARMId () const;

    /** @brief    获取内力计算设置
     * 
     * 
     * @return   当返回 true,则需要计算单元内力
     * @return   
     * @author   wanghuan
     * @date     2025.03.28
     */
    bool GetFIntOutputSetting (bool& all, int& setId ) const;

    // @brief    获取subcase 对应的Parameter参数 /
    const SG::Utility::SGParameter& Data() const;

    // @brief 对参数进行封装，返回值类型和数据库需要的参数类型一致
    SG::Utility::SGParameter Dump() const;

  private:
    SG::Utility::SGParameter m_parameter;
};

inline SG::Utility::SGParameter Subcase::Dump() const
{
    SG::Utility::SGParameter mulitiSubcase;

    std::string id = "";
    ControlInfo controlInfo("SUBCASE");
    if(ParseParameter(controlInfo))
    {
       id = controlInfo.m_Vaule;
    }

    mulitiSubcase.AddValue(id, m_parameter);
    return mulitiSubcase;
}

inline const SG::Utility::SGParameter& Subcase::Data() const
{
  return m_parameter; 
}


// /** @brief 记录用于材料性能计算或传热和结构分析中的热负荷的温度集合设置
//  *
//  */
// // TODO(bug 001) 目前仅解析Type，其他属性待解析
// struct TEMPERATURE
// {
//     enum USED_TYPE : SG::DataStructure::Common::I8
//     {
//         INITIAL_OR_MATERIAL,
//         LOAD,
//     };

//     SG::DataStructure::Common::Id SID      = 0;
//     USED_TYPE                     usedType = INITIAL_OR_MATERIAL;
// };

// /** @brief 求解输出设置
//  *
//  */
// struct OutputSetting
// {
//     // node
//     // static
//     SG::DataStructure::Common::I8 m_SPCFORCE     = 0;  // Requests the form and type of single point force of constraint vector output.
//     SG::DataStructure::Common::I8 m_MPCFORCE     = 0;  // Requests the form and type of multipoint force of constraint vector output.
//     SG::DataStructure::Common::I8 m_GPFORCE      = 0;
//     SG::DataStructure::Common::I8 m_DISPLACEMENT = 0;
//     SG::DataStructure::Common::I8 m_OLOAD        = 0;  // Requests the form and type of applied load vector output.
//     // dynamic
//     SG::DataStructure::Common::I8 m_GPKE = 0;           // Requests the output of the kinetic energy at selected grid
//                                                         // points in normal modes analysis only.
//     SG::DataStructure::Common::I8 m_GPSTRESS      = 0;
//     SG::DataStructure::Common::I8 m_GPSTRAIN      = 0;
//     SG::DataStructure::Common::I8 m_ACCELERATION  = 0;  // Requests form and type of acceleration vector output.
//     SG::DataStructure::Common::I8 m_VECTOR        = 0;
//     SG::DataStructure::Common::I8 m_VELOCITY      = 0;
//     SG::DataStructure::Common::I8 m_SACCELERATION = 0;  // Requests the form and type of solution set acceleration output.
//     SG::DataStructure::Common::I8 m_SDISPLACEMENT = 0;
//     SG::DataStructure::Common::I8 m_SVECTOR       = 0;
//     SG::DataStructure::Common::I8 m_SVELOCITY     = 0;
//     // element
//     // static
//     SG::DataStructure::Common::I8 m_STRESS = 0;
//     SG::DataStructure::Common::I8 m_STRAIN = 0;
//     SG::DataStructure::Common::I8 m_FORCE  = 0;  // element force
//     // dynamic
//     SG::DataStructure::Common::I8 m_ELSTRESS = 0;  // element force
//     SG::DataStructure::Common::I8 m_ELFORCE  = 0;  // element force
//     SG::DataStructure::Common::I8 m_ESE      = 0;  // element force
//     // set
//     SG::DataStructure::Common::I8 m_OMODES     = 0;  // element force
//     SG::DataStructure::Common::I8 m_OFREQUENCY = 0;  // element force
// };

    // char                           m_title[128]    = { 0 };                                ///< 标题
    // char                           m_subTitle[128] = { 0 };                                ///< 副标题

    // SG::DataStructure::Common::I32 m_staticSub     = 0;  ///< 指定静力工况 (屈曲分析计算微分刚度)
    // SG::DataStructure::Common::I64 m_tstep         = 0;  ///< 选择积分和输出时间步骤的线性或非线性瞬态分析。
    // SG::DataStructure::Common::I64 m_loadset       = 0;  ///< 引用的LSEQ条目
    // SG::DataStructure::Common::I64 m_frequency     = 0;  ///< 频响分析中求解点设置，引用freqi条目
    // SG::DataStructure::Common::I64 m_sdamping      = 0;  ///< 阻尼引用项
    // SG::DataStructure::Common::I64 m_ic            = 0;  ///< 瞬态分析的初始条件
    // SG::DataStructure::Common::I64 m_modeSelect =
    //     0;  ///< Selects a subset of the computed modes for inclusion or exclusion in modal dynamic analysis.
    // SG::DataStructure::Common::I64 m_modes = 0;       ///< Repeats a subcase.

    // OutputSetting                  m_out    = { 0 };  ///< 输出设置
    // SG::DataStructure::Common::I64 m_NLPARM = 0;      ///< Selects the parameters used for nonlinear static analysis.
    // std::vector<TEMPERATURE>       m_temperture;      ///< 对于both选项将定义一个MATERIAL一个LOAD

SG_DATASTRUCTURE_FEM_NAMESPACE_CLOSE
